<include file="__THEME__/header" />
<link href="../Public/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/highcharts/modules/exporting.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/raty/jquery.raty.min.js"></script>

<script type="text/javascript">
$(function () {
    var chart;
	// Build the chart
    $('#static').highcharts({
        chart: {
            height:380,
            width:380,
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: true,
            margin: [0,0,0,10]
        },
        title: {
        	align: 'left',
            text: '患者最常用的五种药与提及次数',
            style: {color:'#545454',fontsize:'16px'}
        },
        tooltip: {
    	    pointFormat: '{series.name} <b>{point.percentage:.1f}%</b><br>提及次数： <b>{point.num}<b>'
        },
        legend: {
            layout: 'vertical',
            backgroundColor: '#FFFFFF',
            align: 'left',
            verticalAlign: 'bottom',
			itemMarginTop: 3,
            itemMarginBottom: 3,
            shadow:true
        },        
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true
                },
                showInLegend: true
            }
        },
        credits: {
            enabled: false
        },         
        series: [{
            type: 'pie',
            name: '所占比例：',
            data: [
                // ['药品一',   45.0],
                // ['药品二',   26.8],
                // ['药品三',   8.5],
                // ['药品四',   6.2],
                // {
                    // name: '药品五',
                    // y: 12.8,
                    // sliced: true,
                    // selected: true
                // },
                // {
                    // name: '药品d',
                    // y: 12.8,
                    // num:10
                // },
            ]
        }]
    });
    
    $('#categoryid').change(function() {
    	// alert('123');return;
		var categoryid = $(this).val();
        $.post(APP+"/Index/getStaticByCategoryid",{categoryid:categoryid},function(json){
        	var json = eval("("+json+")");
        	// alert(json.data);return false;
            if(json.status == 1){
		        var chart = $('#static').highcharts();
		        // var data = JSON.stringify(json.data);
		        // series[0].remove();
		        // chart.addSeries({
		            // type: 'pie',
		            // name: '所占比例：',		        	
					// data: json.data
		        // });
		        chart.series[0].setData(json.data['top5']);
		        $("#other").empty();
		        $("#other").append(
					'<table cellpadding="0" cellspacing="0" id="test">'+
						'<tr>'+
							'<th>药品名称</th>'+
							'<th>提及次数</th>'+
						'</tr>'
		        );
		        if(!json.data['other']){
		        	$("#other table").append('<tr><td colspan="2"><center>对不起，暂无相关数据</center></td></tr>')
		        }else{
			        $.each(json.data['other'],function(key, value){
				        $("#other table").append(		        	
							'<tr>'+
								'<td>'+value.name+'</td>'+
								'<td>'+value.num+'次</td>'+
							'</tr>'		        	
				        );
			        });
		        }
		        $("#other").append('</table>');

            }else{
				$("#medicinebox").html('<center>数据通信失败，请稍后再试！<center>');
            }
        });					        

    });
    
    $('#categoryid').triggerHandler('change');
         
    /**
     * 星星评分 
     */
    $(".medicine-box").each(function(i){
    	
    		var $obj = $(this).find(".medicine-bd");
    		var id	= $obj.find("input[name='id']").val();
    
            $.post(APP+"/Index/isCommented",{'id':id},function(json){
        	var json = eval("("+json+")");
        	// alert(json.status);return false;
            if(json.status !== 1){
			    $obj.find('.effect').raty({
			    	 path:"__PUBLIC__/js/raty/img",
			    	 starOff: 'star-off-big.png',
			 		 starOn: 'star-on-big.png',
			 		 hints: ['1分', '2分', '3分', '4分', '5分'],
			 		 size:24,
			 		 scoreName:'effect'
			    });   
			    $obj.find('.side-effect').raty({
			    	 path:"__PUBLIC__/js/raty/img",
			    	 starOff: 'star-off-big.png',
			 		 starOn: 'star-on-big.png',
			 		 hints: ['1分', '2分', '3分', '4分', '5分'],
			 		 size:24,
			 		 scoreName:'side-effect'
			    });   
			    $obj.find('.price').raty({
			    	 path:"__PUBLIC__/js/raty/img",
			    	 starOff: 'star-off-big.png',
			 		 starOn: 'star-on-big.png',
			 		 hints: ['1分', '2分', '3分', '4分', '5分'],
			 		 size:24,
			 		 scoreName:'price'
			    });
            }else{
	        	$obj.find(".effect").raty({ 
					readOnly: true, 
					score: json.data.effect, 
					path:"__PUBLIC__/js/raty/img",
					starOff: 'star-off-big.png',
					starOn: 'star-on-big.png',
					hints: ['1分', '2分', '3分', '4分', '5分'],
					size:24,
					scoreName:'effect'	        		
        		});
	        	$obj.find('.side-effect').raty({
	        		readOnly: true, 
	        		score: json.data.side_effect,
					path:"__PUBLIC__/js/raty/img",
					starOff: 'star-off-big.png',
					starOn: 'star-on-big.png',
					hints: ['1分', '2分', '3分', '4分', '5分'],
					size:24,
					scoreName:'side-effect',	        		 
        		});
	        	$obj.find(".price").raty({ 
	        		readOnly: true, 
	        		score: json.data.price,
					path:"__PUBLIC__/js/raty/img",
					starOff: 'star-off-big.png',
					starOn: 'star-on-big.png',
					hints: ['1分', '2分', '3分', '4分', '5分'],
					size:24,
					scoreName:'price',	        		
        		});		
	        	$obj.find("div .edit").hide();
	        	$obj.find("div .view").show();
	        	$obj.find("div .view").html(json.data.content);  
		    	$obj.find(".sub").hide();
	        	      				
            }
        });	
    })
    
    
    
    /**
     * 收起展开 
     */
    $(".arrow").toggle(
		function(){
	    	$(this).parents(".medicine-box").find(".medicine-bd").show();
	    	$(this).html("收起&nbsp;&uarr;");	    	
	    },function(){
	    	$(this).parents(".medicine-box").find(".medicine-bd").hide();
	    	$(this).html("展开&nbsp;&darr;");
	    });   
	
	/**
	 * 提交药品评论 
	 */    
    $(".sub").click(function(){
    	// $(this).attr('disabled',true);
    	var $obj		 = $(this).parents(".medicine-bd");
    	var id			 = $obj.find("input[name='id']").val();
    	var effect		 = $obj.find("input[name='effect']").val();
    	var sideeffect	 = $obj.find("input[name='side-effect']").val();
    	var price		 = $obj.find("input[name='price']").val();
    	var content		 = $obj.find("textarea").val();
    	
        $.post(APP+"/Index/addComment",{'id':id,'effect':effect,'side_effect':sideeffect,'price':price,'content':content},function(json){
        	var json = eval("("+json+")");
        	// alert(json.data);return false;
            if(json.status == 1){
	        	$obj.find(".effect").raty({ 
					readOnly: true, 
					score: json.data.effect, 
					path:"__PUBLIC__/js/raty/img",
					starOff: 'star-off-big.png',
					starOn: 'star-on-big.png',
					hints: ['1分', '2分', '3分', '4分', '5分'],
					size:24,
					scoreName:'effect'	        		
        		});
	        	$obj.find('.side-effect').raty({
	        		readOnly: true, 
	        		score: json.data.side_effect,
					path:"__PUBLIC__/js/raty/img",
					starOff: 'star-off-big.png',
					starOn: 'star-on-big.png',
					hints: ['1分', '2分', '3分', '4分', '5分'],
					size:24,
					scoreName:'side-effect',	        		 
        		});
	        	$obj.find(".price").raty({ 
	        		readOnly: true, 
	        		score: json.data.price,
					path:"__PUBLIC__/js/raty/img",
					starOff: 'star-off-big.png',
					starOn: 'star-on-big.png',
					hints: ['1分', '2分', '3分', '4分', '5分'],
					size:24,
					scoreName:'price',	        		
        		});
	        	$obj.find("div .edit").hide();
	        	$obj.find("div .view").show();
	        	$obj.find("div .view").html(json.data.content);
	        	$obj.find(".sub").hide();
            }else{
				
            }
        	alert(json.info);
        });	    	
    });
    
    $(".edit").click(function(){
    	var $obj = $(this).parents(".medicine-bd");
    	var content = $obj.find("div .view").val();
    	$obj.find("div .view").hide();
    	$obj.find("div .edit").show();
    	$obj.find("textarea").html(content);
    	
    });
    
});
</script>

<!-- 内容 begin  -->
<div class="content">
	<include file="__THEME__/banner" />
	<include file="__THEME__/apps_wide" />
	<div class="main" >
		<script type="text/javascript" src="../Public/Js/Common.js" ></script>
		<link href="__PUBLIC__/js/pagination/pagination.css" rel="stylesheet" type="text/css" />
		
		<div class="intro">
			<h2>注册病友用药统计及评价</h2>
		</div>
		<div class="layout">
			<div class="static-box">
				<div class="title">
					注册病友用药统计 &nbsp;
					<select name="categoryid" class="select" id="categoryid">
						<volist name="categoryList" id="category">
							<option value="{$category['id']}" <eq name="categoryid" value="$category['id']">selected</eq> >
								{$category['title']}
							</option>
						</volist>
					</select>
				</div>
				<div id="static" style="min-width: 400px; height: auto; margin: 0 auto; float: left;"></div>
				<div class="rank">
					<div class="title">其他被提及药物</div>
					<div id="other"></div>
					<a href="#" class="more">查看所有药物&nbsp;&rsaquo;&rsaquo;</a>
				</div>
			</div>
			<div class="c"></div>
			<div class="comment-box">
				<div class="title">我的用药体会</div>
				<volist name="medicineList" id="medicine">
				<div class="medicine-box">
					<div class="medicine-hd">{$medicine['name']}<span class="arrow">展开&nbsp;&darr;</span></div>
					<div class="medicine-bd" style="display: none;">
						<form method="post">
							<div class="assess">
								评价：
								<div class="item">
									<label>疗效</label>&nbsp;<span class="effect"></span>
								</div>
								<div class="item">
									<label>副作用</label>&nbsp;<span class="side-effect"></span>
								</div>
								<div class="item">
									<label>价格</label>&nbsp;<span class="price"></span>
								</div>
							</div>
							<div class="comment edit">
								 评论：
								 <div class="edit">
						 			<textarea name="content" class="txt"></textarea>
								 </div>
								 <div class="view"></div>
							</div>
							<div class="c"></div>
							<input type="hidden" name="id" value="{$medicine['id']}"/>
							<input type="button" value="提交" class="sub-btn sub"  style="float:right;margin-right: 30px;margin-top:10px;"/>
							<input type="button" value="编辑" class="sub-btn edit"  style="float:right;margin-right: 30px;margin-top:10px;display:none;"/>
							
						</form>
					</div>
				</div>
				</volist>
				
				<!-- <div class="medicine-box">
					<div class="medicine-hd">药物一<span class="allow">&darr;</span></div>
					<div class="medicine-bd">
						<form method="post">
							<div class="assess">
								评价：
								<div class="item">
									<label>疗效</label>&nbsp;5颗星
								</div>
								<div class="item">
									<label>副作用</label>&nbsp;5颗星
								</div>
								<div class="item">
									<label>价格</label>&nbsp;5颗星
								</div>
							</div>
							<div class="comment">
								 评论：
								 <div>
						 			<textarea name="content" class="txt"></textarea>
								 </div>
							</div>
							<div class="c"></div>
							<input type="submit" value="提交信息" class="sub-btn"  style="float:right;margin-right: 50px;margin-top:10px;"/>
						</form>
					</div>
				</div>	 -->			
			</div>
		</div>
		
		<input id="page" type="hidden" value="{$_GET['p']}">
	</div>
	<div class="c"></div>
</div>
<!-- 内容 end -->

<script type="text/javascript">
	$(function(){
		$("#category").change(function(){
			
			var categoryid = $(this).val();
	        $.post(APP+"/Index/getMedicineByCategoryId",{categoryid:categoryid},function(json){
	        	var json = eval("("+json+")");
	        	// alert(json.data);return false;
	            if(json.status == 1){
	            	$("#medicinebox").empty();
	            	$.each(json.data,function(key,value){
	            		$("#medicinebox").append(
	            			'<label><input type="checkbox" name="medicines[]" value='+key+' />'+value+'</label>'
	            		);
	            	});
	            }else{
					$("#medicinebox").html('<center>对不起，暂时还没有相关数据！<center>');
	            }
	        });		
			$('#'+type).show();
			$('#'+type).find("input").removeAttr("disabled");
		});
		
		$("#category").find("option[value={$gcid}]").attr("selected",true);
		$('#category').triggerHandler('change');
	});
	
	function winMedicine() {
		var categoryid = $("#category").children("option:selected").val();
		ymPrompt.win(APP+'/Index/addMedicine/categoryid/'+categoryid,350,200,'添加药物',null,null,null,{id:'a'});
	}
	

</script>


<include file="__THEME__/footer" />

